package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 12/16/20 2:27 PM
 */
public class Mirrors_02 {

    public static void inorderTraversal(TreeNode root) {

        if (root == null) {

            return;
        }

        TreeNode node = root;
        while (node != null) {

            if (node.left != null) {

                TreeNode preNode = node.left;

                while (preNode != null && preNode.right != null && preNode.right != node) {

                    preNode = preNode.right;
                }

                if (preNode.right == null) {

                    preNode.right = node;
                    node = node.left;
                }else {

                    System.out.println(node.val);
                    preNode.right = null;
                    node = node.right;
                }
            }else {

                System.out.println(node.val);
                node = node.right;
            }
        }

    }
}
